using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using StateManagement.Models;
using System;
using System.Linq;

namespace Statemanagement.Models {
  public class BookDbSeeder {
    public static void Seed(IServiceProvider serviceProvider) {
      using var context = new BookDbContext(serviceProvider.GetRequiredService<DbContextOptions<BookDbContext>>());

      // Look for any books.
      if (context.Books.Any()) {
        //if we get here then data already seeded
        return;
      }

      context.Books.AddRange(
        new Book() { Id=1, ISBN = "0000", Title = "Book0", Author = "Author0", Year = 2019, Price = 0F },
        new Book() { Id=2, ISBN = "1111", Title = "Book1", Author = "Author1", Year = 2020, Price = 100F },
        new Book() { Id=3, ISBN = "2222", Title = "Book2", Author = "Author2", Year = 2020, Price = 200F },
        new Book() { Id=4, ISBN = "3333", Title = "Book3", Author = "Author3", Year = 2021, Price = 300F },
        new Book() { Id=5, ISBN = "4444", Title = "Book4", Author = "Author4", Year = 2021, Price = 400F },
        new Book() { Id=6, ISBN = "5555", Title = "Book5", Author = "Author5", Year = 2022, Price = 500F }
      );

      context.SaveChanges();
    }
  }
}


